package com.probox.modules.controller.customer;

import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.entity.domain.customer.CustomerTaskInfo;
import com.probox.common.entity.service.customer.ICustomerTaskInfoService;
import com.probox.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/**
 * 会员任务Controller
 *
 * @author usoft
 * @date 2022-09-19
 */
@RestController
@RequestMapping("/customer/task")
public class CustomerTaskController extends BaseController {
    @Autowired
    private ICustomerTaskInfoService customerTaskInfoService;

    /**
     * 查询会员任务列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CustomerTaskInfo customerTaskInfo) {
        startPage();
        List<CustomerTaskInfo> list = customerTaskInfoService.queryList(customerTaskInfo);
        return getDataTable(list);
    }

    @GetMapping("/select")
    public AjaxResult select(CustomerTaskInfo customerTaskInfo) {
        List<CustomerTaskInfo> list = customerTaskInfoService.queryList(customerTaskInfo);
        return AjaxResult.success(list);
    }


    /**
     * 导出会员任务列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerTaskInfo customerTaskInfo) throws IOException {
        List<CustomerTaskInfo> list = customerTaskInfoService.queryList(customerTaskInfo);
        ExcelUtil<CustomerTaskInfo> util = new ExcelUtil<CustomerTaskInfo>(CustomerTaskInfo.class);
        util.exportExcel(response, list, "会员任务数据");
    }

    /**
     * 获取会员任务详细信息
     */
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId) {
        return AjaxResult.success(customerTaskInfoService.selectCustomerTaskInfoById(taskId));
    }

    /**
     * 新增会员任务
     */
    @PostMapping("/addTask")
    public AjaxResult add(@RequestBody CustomerTaskInfo customerTaskInfo) {
        return toAjax(customerTaskInfoService.insertCustomerTaskInfo(customerTaskInfo));
    }

    /**
     * 修改会员任务
     */
    @PreAuthorize(hasPermi = "system:rule:edit")
    @PutMapping("/updateTask")
    public AjaxResult edit(@RequestBody CustomerTaskInfo customerTaskInfo) {
        return toAjax(customerTaskInfoService.updateCustomerTaskInfo(customerTaskInfo));
    }

    /**
     * 修改会员任务状态
     */
    @PreAuthorize(hasPermi = "system:brand:edit")
    @PutMapping("/updateTaskStatus")
    public AjaxResult editA(@RequestBody CustomerTaskInfo customerTaskInfo) {
        return toAjax(customerTaskInfoService.updateById(customerTaskInfo));
    }

    /**
     * 删除会员任务
     */
    @DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds) {
        return toAjax(customerTaskInfoService.deleteCustomerTaskInfoByIds(taskIds));
    }
}
